<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>传送门</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      .box {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: 0;
        background-color: rgba(0, 0, 0, 0.5);
        display: flex;
        justify-content: center;
        align-items: center;
      }
      .dialog {
        width: 500px;
        min-height: 500px;
        background-color: #fff;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="show = true ">打开模态框</button>
      <teleport to="body">
        <div v-if="show" class="box" @click.self="show = false">
          <div class="dialog">
            <span @click="show = false">X</span>
          </div>
        </div>
      </teleport>
    </div>
  </body>
  <script src="../lib/vue.global.js"></script>
  <script>
    const app = Vue.createApp({
      data() {
        return {
          show: false,
        };
      },
    }).mount("#app");
  </script>
</html>
